package atempdao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import util.HibernateUtil;
import dao.EgnScenario;

public class EgnScenarioDao {
	private final static Logger logger = LoggerFactory.getLogger(EgnScenarioDao.class);

	public static List<EgnScenario> getAllEgnScenario() {
		List<EgnScenario> rst ;
		Session s = HibernateUtil.currentSession();
		logger.debug("Get all EgnScenario instance");
		Query qr = s.createQuery("from EgnScenario" );

		try {
			rst = qr.list();
			HibernateUtil.closeSession();
			return rst;
		} catch (RuntimeException re) {
			logger.error("failed", re);
			HibernateUtil.closeSession();
			throw re;
		}
	}
	public static List<EgnScenario> getEgnScenario(String sceSetId) {
		List<EgnScenario> rst ;
		Session s = HibernateUtil.currentSession();
		logger.debug("Get all EgnScenario instance");
		
		Query qr = s.createQuery("from EgnScenario a where a.sceSetId =:param" );
		qr.setParameter("param", sceSetId);
		try {
			rst = qr.list();
			HibernateUtil.closeSession();
			return rst;
		} catch (RuntimeException re) {
			logger.error("failed", re);
			HibernateUtil.closeSession();
			throw re;
		}
	}
	
	public static List<String> getEgnScenaioSetId() {
		List<String> rst ;
		Session s = HibernateUtil.currentSession();
		logger.debug("Get all EgnScenario instance");
		Query qr = s.createQuery("select distinct a.sceSetId from EgnScenario a" );

		try {
			rst = qr.list();
			HibernateUtil.closeSession();
			return rst;
		} catch (RuntimeException re) {
			logger.error("failed", re);
			HibernateUtil.closeSession();
			throw re;
		}
	}

}
